package com.idez.androiddelphi.utils;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

import com.idez.androiddelphi.model.Usuario;

@MessageDriven(activationConfig = {
		@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
		@ActivationConfigProperty(propertyName = "destination", propertyValue = "java:/queue/test") })
public class ConsumidorJms implements MessageListener {

	@EJB
	private MailSenderEJB ms;

	@Override
	public void onMessage(Message message) {
		ObjectMessage objMsg = (ObjectMessage) message;

		try {
			Usuario u = (Usuario) objMsg.getObject();
			System.out.println("[ConsumidorJms.onMessage] Usuário: "
					+ u.getNome());
			ms.enviarMsgCadastro(u);
		} catch (JMSException e) {
			e.printStackTrace();
		}

	}

}
